<template>
	<view class="page index">
		<view class="form">
			<common-input
			  title="项目当前阶段" 
				v-model="progress"
				:border-bottom="false"
				:disabled="true"
				:require="false"
			>
			</common-input>
			<picker mode="date" @change="selectStartTime">
				<view class="picker">
					<common-input
					  title="暂停开始日期" 
						placeholder="请填写暂停开始日期" 
						v-model="startTime"
						:border-bottom="false"
						:disabled="true"
					>
					</common-input>
				</view>
			</picker>
			<picker mode="date" @change="selectEndTime">
				<view class="picker">
					<common-input
					  title="预计恢复日期" 
						placeholder="请填写预计恢复日期" 
						v-model="endTime"
						:disabled="true"
						:require="false"
					>
					</common-input>
				</view>
			</picker>
			<view class="text">
				<view class="title">
					<view>
						申请暂停原因说明
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="reason" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<update-file title="凭证附件" @update="updatefiles"></update-file>
		</view>
		<view class="footer">
			<button @click="save">提交审批</button>
		</view>
	</view>
</template>

<script>
	import commonInput from "@/components/commonInput.vue";
	import updateFile from "@/components/updateFile.vue";
	import {applyPauseProjectApi} from "@/api/project_api.js";
	export default{
		data() {
			return{
				id: 0,//项目id
				progress:'',
				startTime: '',
				endTime: '',
				reason: '',
				fileUrls: []
			}
		},
		components: {
			commonInput,
			updateFile
		},
		onLoad(e) {
			this.id = e.id;
			this.progress = e.progress
		},
		methods:{
			updatefiles(e){
				this.fileUrls = e.map(item => item.path)
			},
			// 开始时间
			selectStartTime(e){
				this.startTime = e.detail.value;
			},
			// 恢复时间
			selectEndTime(e){
				this.endTime = e.detail.value;
			},
			save(){
				if(this.startTime == ''){
					uni.showToast({
						icon: 'none',
						title: '暂停开始日期不能为空'
					})
					return;
				}
				if(this.reason == ''){
					uni.showToast({
						icon: 'none',
						title: '请输入暂停原因'
					})
					return;
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				})
				applyPauseProjectApi({
					projectId: this.id,
					pauseDate: this.startTime,
					restoreDate: this.endTime,
					reason: this.reason,
					fileUrls: this.fileUrls
				}).then(() => {
					uni.hideLoading();
					uni.showToast({
						icon: 'success',
						title: '操作成功！'
					})
					setTimeout(() => {
						uni.navigateBack();
					},1500)
				}).catch(() => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/style/customicons.scss";
	.index{
		padding: 24rpx 0;
		@include flex-c;
		.form{
			flex: 1 0 0;
			overflow: auto;
			.text{
				border-bottom: 4rpx #e5e5e5 solid;
				padding: 12rpx 30rpx;
				.title{
					font-size: 28rpx;
					color: #101010;
					padding: 0 0 16rpx;
					display: flex;
					align-items: center;
					.require{
					  height: 28rpx;
					  width: 6rpx;
					  background-color: #c24135;
					  margin-left: 10rpx;
				  }
				}
				textarea{
					font-size: 28rpx;
					color: #909090;
					height: 125rpx;
				}
				.place{
					font-size: 28rpx;
					color: #909090;
				}
			}
			&::-webkit-scrollbar{
				display: none;
			}
		}
		.footer{
			flex: 0 0 auto;
			padding: 24rpx 130rpx;
			button{
				@include button;
				background-color: #198AFA;
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				width: 100%;
			}
		}
	}
</style>